import axios from "../utils/http";

const UserStore = {
    namespaced: true,
    state: () => ({
        user_list: [],
        count:0,
    }),
    mutations: {
        UserMutations(state, list) {
            state.user_list = list
        },
        UserCountMutation(state,count){
            state.count = count
        }
    },
    actions: {
        UserActions(context, page = { page: 1, size: 10 }) {
            var url = "/api/userlist?page=" + page.page + "&size=" + page.size
            axios.get(url).then(
                res => {
                    if (res.code === 200) {
                        context.commit("UserMutations", res.list)
                    }
                }
            )
        },
        UserCountAction(context){
            axios.get("/api/usercount").then(
                res=>{
                    if(res.code === 200){
                        context.commit('UserCountMutation',res.list[0].total)
                    }
                }
            )
        }
    }
}

export default UserStore